import { fromJS } from 'immutable'
import * as types from './action-types'

const defaultState = fromJS({
  topicList: [],
  articleList: [],
  recommendList: [],
  writerList: [],
  articlePage: 1,
  showBackTop: false
})

export default (state = defaultState, action) => {
  switch (action.type) {
    case types['SET_HOME_DATA']:
      return state.merge({
        topicList: action.topicList,
        articleList: action.articleList,
        recommendList: action.recommendList,
        writerList: action.writerList
      })
    case types['ADD_HOME_DATA']:
      return state.merge({
        'articleList': state.get('articleList').concat(action.data),
        'articlePage': action.page
      })
    case types['CHANGE_BACK_TOP']:
      return state.set('showBackTop', action.show)
    default:
      return state
  }

}
